package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class TotalSale here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SaleContainer
{
    private ArrayList<Sale> saleList;
    
    /**
     * Constructor for objects of class TotalSale
     */
    public SaleContainer()
    {
        saleList = new ArrayList<Sale>();
    }
    
    public void createSalesList(long _id, SalesList _salesList)
    {
        getSale(_id).createSalesList(_salesList);
    }
    
    public Sale getSale(long _id)
    {
        Sale s = new Sale();
        s = null;
        for (int i=0; i<saleList.size(); i++)
        {
            if (saleList.get(i).getId() == _id)
            { 
                s =saleList.get(i);
                return s;
            }
            else
                s = null;
        }
        
        return s;
    }
    
    public void createSale(Sale _sale)
    {
        saleList.add(_sale);
    }
    
    public void updateSale(Sale _sale)
    {
        getSale(_sale.getId()).setId(_sale.getId());
        getSale(_sale.getId()).setDate(_sale.getDate());
        getSale(_sale.getId()).setDescription(_sale.getDescription());
    }
    
    public void removeSale(long _id)
    {
        for(int i=0; i<saleList.size(); i++)
        {
            if (saleList.get(i).getId() == _id) 
            {
                saleList.remove(i);
                //sale.getSellItem().setStock(sale.getSellItem().getStock()+sale.getQuantity());
            }
        }
    }
    
    public ArrayList<Sale> listAllSales()
    {
        return saleList;
    }
    
}
